package com.jm.springboot21.mapper;

import com.jm.springboot21.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {
    //根据id显示用户
    @Select("SELECT * FROM user WHERE id = #{id}")
    User findById(Integer id);
    // 注册插入用户
    @Insert(" INSERT INTO user (username, password, email) VALUES (#{username}, #{password}, #{email})")
    void register(User user);

    // 根据用户名和密码登录
    @Select("SELECT * FROM user WHERE username = #{username} AND password = #{password}")
    User login(String username,String password);
    //修改用户
    @Update("<script>" +
            "UPDATE user " +
            "<set>" +
            "    <if test='username != null'>username = #{username},</if>" +
            "    <if test='password != null'>password = #{password},</if>" +
            "    <if test='name != null'>name = #{name},</if>" +
            "    <if test='age != null'>age = #{age},</if>" +
            "    <if test='email != null'>email = #{email},</if>" +
            "</set>" +
            "WHERE id = #{id}" +
            "</script>")
    boolean update(User user);
}
